const express = require('express');
const router = express.Router();
const fstool = require('../model/fsTool.js');
const path = require('path');

const pathname = path.join(__dirname,'..','albums');
const pathname2 = path.join(__dirname,'..','public','img');


//监听首页路由
router.get('/',function(req,res,next){
    fstool.getPhotoDirName(pathname,function(err,files){
        if(err){return next(err)}
        res.render('index.njk',{"albumArr":files})
    })
})

// router.get('/',function(req,res,next){
//     fstool.getPhotoDirName(pathname,function(err,files){
//         if(err){return next(err)}
//         res.render('../view/index.njk',{"imgArr":files})
//     })
// })


router.get('/:name',function(req,res,next){
    fstool.getPhotoDirName(path.join(pathname,req.params.name),function(err,files){
        if(err){return next(err)}
        res.render('photo.njk',{"photoArr":files})
    })
})


module.exports = router;